
var new_vecfile = dag["dagdir"] + "/vec.shp" ;
 
var cmd1 = "/usr/bin/ogr2ogr -t_srs '+proj=stere +lat_0=90 +lat_ts=60 +lon_0=-80 +k=1 +x_0=0 +y_0=0 +a=6378137 +b=6356257 +units=m +no_defs ' "
    + new_vecfile + " " + input["vector"] ;
 
var res1 = bash_operator("task-id-1", cmd1) ;
 
var outjson = dag["dagdir"] + "/output.json" ;

log(outjson) ;
 
var cmd2="/home/hadoop/coding/zonalstat_many/codeblock/bin/Release/zonalstat_many 0 100 -9 "
    + new_vecfile
    + " /home/hadoop/Downloads/ims/Month/sce_mon_{yyyymmdd}.tif "
    +  (input["wholeymd0"]) + " "
    +  (input["wholeymd1"]) + " "
    +  (input["isrepeat"]) + " "
    +  (input["mmdd0"]) + " "
    +  (input["mmdd1"]) + " "
    +  (input["mmdd1nextyear"]) + " "
    + outjson ;
 
var res2 = bash_operator("task-id-2", cmd2 ) ;

//read json
log("debug-1 0 0 0 ") ;
var jdata = json_from_file( outjson ) ;
log("debug-1") ;
log( String(jdata.xdata[1]) ) ;


//read csv
var csvfilename = outjson + ".csv" ;
var arr2d = read_2darray_from_file( csvfilename , ',' , true ) ;
log("debug-2") ;
log( String(arr2d[1][1] ) ) ;

//write 2d array
var testdata2d = [[1,2,3] , [4,5,6] , [7.0,8.0,9.0] , [99,100,101.0]] ;
var testfile1 = dag["dagdir"] + "/testdata1.csv" ;
write2darray_to_file( testdata2d ,testfile1 ) ;
log(testfile1) ;

//write json text
var testfile2 = dag["dagdir"] + "/testfile2.json" ;
var testobject = {name:'Mike' , age:38 , college:'PekkingUniv'} ;
writetext_to_file( JSON.stringify(testobject)  , testfile2) ;
log(testfile2);